import { API_URL, MyAjax, CODE } from '../config';

export const list_servs = 'list_servs';

export function function_list_servs (projectId, dispatch, cb) {
  MyAjax(API_URL.listServers, {
    projectId
  }, (result) => {
    if (result.code === CODE.SUCCESS) {
      dispatch({
        type: list_servs,
        list: result.data
      });
      cb(result.data);
    }
  });
}

export function function_edit_servs (
  projectId,
  servsId,
  dispatch,
  serviceName,
  reponsitoryDirectory,
  targetBranch,
  lineHost,
  testHost,
  prevHost,
  lineHostDirectory,
  lineDb,
  testDb,
  commandBeforePackage,
  packageDir,
  excludeFiles,
  commandBeforeDeploy,
  commandAfterDeploy,
  udtGitDir,
  jobType,
  lineJobHost,
  isTestJobDeployed,
  isPrevJobDeployed,
  cb) {
  MyAjax(API_URL.editServersById, {
    projectId,
    servsId,
    serviceName,
    reponsitoryDirectory,
    targetBranch,
    lineHost,
    testHost,
    prevHost,
    lineHostDirectory,
    lineDb,
    testDb,
    commandBeforePackage,
    packageDir,
    excludeFiles,
    commandBeforeDeploy,
    commandAfterDeploy,
    udtGitDir,
    jobType,
    lineJobHost,
    isTestJobDeployed,
    isPrevJobDeployed,
  }, result => {
    cb(result);
  })
}

export function function_get_servs (servsId, dispatch, cb) {
  MyAjax(API_URL.getServerById, {
    servsId: servsId
  }, result => {
    if (result.code === CODE.SUCCESS) {
      cb(result.data);
    }
  })
}

export function function_add_servs (
  projectId,
  dispatch,
  serviceName,
  reponsitoryDirectory,
  targetBranch,
  lineHost,
  testHost,
  prevHost,
  lineHostDirectory,
  lineDb,
  testDb,
  commandBeforePackage,
  packageDir,
  excludeFiles,
  commandBeforeDeploy,
  commandAfterDeploy,
  udtGitDir,
  jobType,
  lineJobHost,
  isTestJobDeployed,
  isPrevJobDeployed,
  cb
) {
  MyAjax(API_URL.addServersByProject, {
    projectId,
    serviceName,
    reponsitoryDirectory,
    targetBranch,
    lineHost,
    testHost,
    prevHost,
    lineHostDirectory,
    lineDb,
    testDb,
    commandBeforePackage,
    packageDir,
    excludeFiles,
    commandBeforeDeploy,
    commandAfterDeploy,
    udtGitDir,
    jobType,
    lineJobHost,
    isTestJobDeployed,
    isPrevJobDeployed,
  }, (result) => {
    cb(result);
  });
}